package gui;

import java.awt.GridLayout;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JLayeredPane;
import javax.swing.JPanel;
import javax.swing.OverlayLayout;
import model.GameField;
import model.GameTile;
import model.Settings;

/**
 *
 * @author Joachim
 */
public class Screen extends JFrame{
    GameField field;
    JLayeredPane playField;
    JPanel background;
    JPanel foreground;
    
    public Screen (GameField field) {
        this.field = field;
        init();
    }
    
    private void init() {
        playField = new JLayeredPane();
        background = new JPanel(new GridLayout(Settings.GAME_HEIGHT_IN_TILES, Settings.GAME_WIDTH_IN_TILES), true);
        foreground = new JPanel(true);
        playField.setSize(Settings.SCREEN_WIDTH-Settings.H_OFFSET, Settings.SCREEN_HEIGHT-Settings.V_OFFSET);
        background.setSize(Settings.SCREEN_WIDTH-Settings.H_OFFSET, Settings.SCREEN_HEIGHT-Settings.V_OFFSET);
        foreground.setSize(Settings.SCREEN_WIDTH-Settings.H_OFFSET, Settings.SCREEN_HEIGHT-Settings.V_OFFSET);
        
        for (GameTile[] gameTileRow : field.getField()) {
            for (GameTile gameTile : gameTileRow) {
                background.add(new JLabel(gameTile.getIcon()));
            }
        }
        
        foreground.setOpaque(false);
        playField.add(foreground);
        playField.add(background);
        
        this.setSize(Settings.SCREEN_WIDTH, Settings.SCREEN_HEIGHT);
        this.add(playField);
        this.addKeyListener(new MyKeyListener());
        this.setVisible(true);
        //this.setResizable(false);
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);
    }
    
    private class MyKeyListener implements KeyListener {

        @Override
        public void keyTyped(KeyEvent e) {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public void keyPressed(KeyEvent e) {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public void keyReleased(KeyEvent e) {
            throw new UnsupportedOperationException("Not supported yet.");
        }
        
    }
}
